package cn.itcast.health.admin.controller;

import cn.itcast.health.admin.logs.OperationLog;
import cn.itcast.health.commons.entity.QueryPageBean;
import cn.itcast.health.commons.entity.Result;
import cn.itcast.health.commons.utils.LogUtils;
import cn.itcast.health.interfaces.service.CheckitemService;
import cn.itcast.health.pojo.CheckItem;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkitem")
public class CheckitemController {

    @Reference
    private CheckitemService checkitemService;


    @PostMapping("/addCheckItemData.do")
    @PreAuthorize("hasAuthority('CHECKITEM_EDIT')")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.ADD, operationContent = "添加检查项的数据")
    public Result addCheckItemData(@RequestBody CheckItem checkItem){
        Result result = checkitemService.addCheckItemData(checkItem);
        return result;
    }

    @GetMapping("/findByPageCheckitemData.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "分页查询检查项的数据")
    public Result findByPageCheckitemData(QueryPageBean queryPageBean){
        Result result = checkitemService.findByPageCheckitemData(queryPageBean);
        return result;
    }

    @PutMapping("/updateCheckItemData.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.MODIFY, operationContent = "修改检查项的数据")
    public Result updateCheckItemData(@RequestBody CheckItem checkItem){
        Result result = checkitemService.updateCheckItemData(checkItem);
        return result;
    }

    @DeleteMapping("/deleteByIdCheckItemData.do")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.DELETE, operationContent = "逻辑删除检查项的数据")
    public Result deleteByIdCheckItemData(@RequestBody CheckItem checkItem){
        Result result = checkitemService.deleteByIdCheckItemData(checkItem.getId());
        return result;
    }

}
